// Written by Craig'n'Dave
using System;
// Queue using objects
namespace ConsoleApp1
{
    class Program
    {
        public class Queue
        {
            private class Node
            {
                public string data;
                public Node pointer;
            }

            private Node front_pointer;
            private Node back_pointer;

            public bool enqueue(string item)
            {
                // Check queue overflow
                try
                {
                    // Enqueue the item
                    Node new_node = new Node();
                    new_node.data = item;
                    // Empty queue
                    if (back_pointer == null)
                    {
                        front_pointer = new_node;
                    }
                    else
                    {
                        back_pointer.pointer = new_node;
                    }
                    back_pointer = new_node;
                    return true;
                }
                catch
                {
                    return false;
                }
            }

            public string dequeue()
            {
                // Check queue underflow
                if (front_pointer != null)
                {
                    // Dequeue the item
                    string item = front_pointer.data;
                    front_pointer = front_pointer.pointer;
                    // When the last item is dequeued reset the pointers
                    if (front_pointer == null)
                    {
                        back_pointer = null;
                    }
                    return item;
                }
                else
                {
                    return null;
                }
            }

            public string peek()
            {
                // Check queue underflow
                if (front_pointer != null)
                {
                    // Peek the item
                    return front_pointer.data;
                }
                else
                {
                    return null;
                }
            }
        }

        // Main program starts here
        static void Main(string[] args)
        {
            string[] items = new string[] { "Florida", "Georgia", "Delaware", "Alabama", "California" };
            Queue q = new Queue();
            // Add items to the queue
            for (int index = 0; index < items.Length; index++)
            {
                q.enqueue(items[index]);
            }
            // Remove items from the queue
            Console.WriteLine(q.dequeue());
            // Output the next item in the queue
            Console.WriteLine(q.peek());
        }
    }
}
